import java.util.HashMap;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution522 {

    public static void main(String args[]) {
        Solution522 s = new Solution522();
        System.out.println(s.findLUSlength(new String[]{"aabaa", "aca", "aabaa"}));
//        System.out.println(s.lcs("aaa","aabaa"));
    }

    public int findLUSlength(String[] strs) {
        int maxv = -1;
        for (int i = 0; i < strs.length; i++) {
            int flag = 0;
            for (int j = 0; j < strs.length; j++) {
                if (j == i) {
                    continue;
                }
                if (lcs(strs[i], strs[j])) {
                    flag = 1;
                }
            }
            if (flag == 0) {
                maxv = Math.max(maxv, strs[i].length());
            }
        }
        return maxv;
    }

    public boolean lcs(String a, String b) {
        int n = a.length();
        int m = b.length();
        int[][] dp = new int[n + 1][m + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (a.charAt(i) == b.charAt(j)) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                } else {
                    dp[i + 1][j + 1] = Math.max(dp[i + 1][j], dp[i][j + 1]);
                }
            }
        }
        if (dp[n][m] == a.length()) {
            return true;
        }
        return false;
    }
}
